package stark.app.frame.banner;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.util.BannerUtils;

import java.util.List;

import stark.app.R;

/**
 * 自定义布局，图片+标题
 */

public class TestAdapter extends BannerAdapter<DataBean, TestAdapter.ImageTitleHolder> {
    Context mContext;
    RequestOptions options = new RequestOptions();

    public TestAdapter(List<DataBean> mDatas, Context context) {
        super(mDatas);
        mContext = context;
    }

    @Override
    public ImageTitleHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new ImageTitleHolder(BannerUtils.getView(parent, R.layout.banner_image_title));
    }

    @Override
    public void onBindView(ImageTitleHolder holder, DataBean data, int position, int size) {
        Glide.with(mContext)
                .load(data.imageUrl)
                .apply(options)
                .into(holder.imageView);
        holder.title.setText(data.title);
    }

    public class ImageTitleHolder extends RecyclerView.ViewHolder {
        public ImageView imageView;
        public TextView title;

        public ImageTitleHolder(@NonNull View view) {
            super(view);
            imageView = view.findViewById(R.id.image);
            title = view.findViewById(R.id.bannerTitle);
        }
    }

}
